package com.kang.es.service.impl;

import com.kang.es.dao.ItemRepository;
import com.kang.es.pojo.Item;
import com.kang.es.service.ItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ItemServiceImpl implements ItemService {

    @Autowired
    private ItemRepository itemRepository;

    public void save(Item item) {
        this.itemRepository.save(item);
    }

    public void delete(Item item) {
        this.itemRepository.delete(item);
    }

    public void saveAll(List<Item> items) {
        this.saveAll(items);
    }

    public Iterable<Item> findAll() {
        return this.itemRepository.findAll();
    }

    public Page<Item> findAllPage(int i, int i1) {
        return this.itemRepository.findAll(PageRequest.of(i,i1));
    }

    public List<Item> findByTitleAndContent(String title, String content) {
        return this.itemRepository.findByTitleAndContent(title, content);
    }

    public Page<Item> findByTitleOrContent(String title, String content, int page, int rows) {
        return this.itemRepository.findByTitleOrContent(title, content, PageRequest.of(page, rows));
    }

    public Page<Item> findByTitleAndContentAndIdBetween(String title, String Content, Long min, Long max, Integer page, Integer rows) {
        return this.itemRepository.findByTitleAndContentAndIdBetween(title
                , Content, min, max, PageRequest.of(page, rows));

    }
}
